package com.m1book.domain.auth;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.m1book.domain.user.Miser;
import com.m1book.domain.user.MiserRole;

public class MiserDetails implements UserDetails {
	private static final long serialVersionUID = -1260943946241481979L;
	
	private Miser miser;
	
	public MiserDetails(Miser miser) {
		this.miser = miser;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		Set<MiserRole> roles = new HashSet<MiserRole>();
		roles.add(miser.getRole());
		return roles;
	}

	@Override
	public String getPassword() {
		return miser.getPassword();
	}

	@Override
	public String getUsername() {
		return miser.getAccount();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public Miser getMiser() {
		return miser;
	}

}
